<template>
    <div>

        授权中 -- {{ code }}
    </div>
</template>

<script setup>
import axios from 'axios';
import { useRoute, useRouter } from 'vue-router';


const route = useRoute()
const router = useRouter()
// 获取地址栏参数code
const code = route.query.code

const _get_message = () =>{
    axios.post('https://gitee.com/oauth/token', {
        grant_type: 'authorization_code',
        code: code,
        client_id: 'd4818f856905e5eeeaec0f9a640d6942af36656e88cc4c67eeff776ed8fe5127',
        redirect_uri: 'http://localhost:5173/oauth/xielin',
        client_secret: 'c401f0b3814809eef78d69dba83aeefa499ab326a42a4a70b9382a5bae8a294a'
    }).then(res =>{
        console.log(res);
        // 如果接口返回成功，就把两个token存到本地，并且跳转到首页
        if(res.status === 200){
            localStorage.setItem('access_token', res.data.access_token)
            localStorage.setItem('refresh_token', res.data.refresh_token)

            router.push({
                path: '/'
            })
        }
        
    })
}

_get_message()


</script>